<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="author" content="李愧愧">
    <title></title>
    <style>
        main{
            width: 590px;
            height: 470px;
            margin: 0 auto;
            position: relative;
        }
        img{
            width: 100%;
            height: 100%;
            position: absolute;
            /* display: none; */
            opacity: 0;
            transition: all 0.3s;
        }
        img.active{
            /* display: inline-block; */
            opacity: 1;
        }
        ul{
            list-style: none;
            position: absolute;
            z-index: 100;
            width: 100%;
            bottom: 20px;
            padding: 0;
            text-align: center;
        }
        li{
            width: 20px;
            height: 20px;
            /* float: left; */
            background-color: white;
            border-radius: 50%;
            margin: 5px;
            display: inline-block;
            transition: all 0.5s;
        }
        li.active{
            background-color: violet;
        }
    </style>
</head>
<body>
    <main>
        <div>
            <img class="active" src="./img/1.jpg" alt="">
            <img src="./img/2.webp" alt="">
            <img src="./img/3.jpg" alt="">
            <img src="./img/5.webp" alt="">
        </div>
        <ul>
            <li class="active"></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
    </main>
<script>
    var imgs = document.querySelectorAll("img")
    var lis = document.querySelectorAll("ul li");
    console.log(imgs)
    var index = 0;//记录当前展示的图片索引
    // 切换图片(轮播)的函数
    function change(){
        imgs[index].className=""
        lis[index].className=""
        index++;
        // 最后一张结束后循环索引
        if(index > 3){
            index = 0;
        }
        imgs[index].className="active"
        lis[index].className="active"
        // 总结：循环操作数据常规步骤
        // 1.还原视图 2.更新索引 3.判断边界 4.更新视图
        
    }
    setInterval(change,2000);
</script>
</body>
</html>